package com.basin.common.neo4j.config;

import org.neo4j.driver.Driver;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager;
import org.springframework.data.neo4j.core.transaction.ReactiveNeo4jTransactionManager;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.repository.config.EnableReactiveNeo4jRepositories;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.ReactiveTransactionManager;

/**
 * @author: Sam ZHONG | sammy1997@aliyun.com
 * @date: 2025/6/3 18:55
 * @description:
 */
@Configuration
@EnableNeo4jRepositories(
        basePackages = {"${neo4j.repositories.base-packages:com.basin.*.neorepo}"},
        transactionManagerRef = "neo4jTransactionManager"
)
@EnableReactiveNeo4jRepositories(
        basePackages = {"${neo4j.repositories.base-packages:com.basin.*.neorepo}"},
        transactionManagerRef = "reactiveTransactionManager1"
)
public class BasinNeo4jConfig {
    @Bean("neo4jTransactionManager")
    public PlatformTransactionManager neo4jTransactionManager(@Qualifier("neo4jDriver") Driver driver) {
        return new Neo4jTransactionManager(driver);
    }

    @Bean("reactiveTransactionManager1")
    public ReactiveTransactionManager reactiveTransactionManager(@Qualifier("neo4jDriver") Driver driver) {
        return new ReactiveNeo4jTransactionManager(driver);
    }
}
